package ar.com.spsolutions.splilabrary.view.pages.home;

import org.apache.log4j.Logger;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.resource.ContextRelativeResource;

import ar.com.spsolutions.splibrary.book.Book;

public class RankingBookPanel extends Panel {

	private static final long serialVersionUID = -9001323223107459743L;

	protected static final Logger LOG = Logger
			.getLogger(RankingBookPanel.class);

	private Book book;

	public RankingBookPanel(final String id, final Book book) {
		super(id);
		this.setBook(book);
		this.addComponents();
	}

	private void addComponents() {
		final Form<Book> form = new Form<Book>("formBook");

		final String pic = this.getBook().getPic();
		form.add(new Image("pic", new ContextRelativeResource(pic == null ? ""
				: pic)));

		final Link<Book> titleLink = new Link<Book>("title") {
			private static final long serialVersionUID = -8647466594354964539L;

			@Override
			public void onClick() {
				// por ahora nada!
			};

		};

		final String titulo = this.getBook().getTitle();
		final Label title = new Label("titleBook", titulo);
		titleLink.add(title);
		form.add(titleLink);

		final Integer stars = this.getBook().getStars();
		final Label star = new Label("star", stars.toString());
		form.add(star);

		this.add(form);
	}

	public Book getBook() {
		return this.book;
	}

	public void setBook(final Book book) {
		this.book = book;
	}

}
